/**基本物件派生类：点
 * date:2011 4 10
 * author zzy
 **/
package cn.edu.dlut.WingGame.Object;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL10;

import cn.edu.dlut.WingGame.BaseType.WingColor;
import cn.edu.dlut.WingGame.Graphic.GLDevice;

public class WingPoint extends WingObject {
	private float x = 0;
	private float y = 0;
	private float pointSize = 1; // 点的大小
	private WingColor pointColor = new WingColor(); // 点的颜色

	public void setPointPos(float x, float y) {
		this.x = x;
		this.y = y;
	}

	public void setPointColor(WingColor pointColor2) {
		pointColor.alpha = pointColor2.alpha;
		pointColor.b = pointColor.b;
		pointColor.g = pointColor.g;
		pointColor.r = pointColor.r;
	}

	public void setPointSize(float size) {
		pointSize = size;
	}

	public WingPoint() {
	}

	public WingPoint(float x, float y, float size, WingColor color) {
		this.x = x;
		this.y = y;
		pointSize = size;
		setPointColor(color);
	}

	public void drawPoint() {
		ByteBuffer vbb = ByteBuffer.allocateDirect(8);
		vbb.order(ByteOrder.nativeOrder());
		FloatBuffer vertices = vbb.asFloatBuffer();
		vertices.put(x);
		vertices.put(y);
		vertices.position(0);

		if (pointColor.hasAlpha())
			GLDevice.enableBlend();
		GLDevice.getGL().glVertexPointer(2, GL10.GL_FLOAT, 0, vertices);
		GLDevice.getGL().glEnableClientState(GL10.GL_VERTEX_ARRAY);
		GLDevice.getGL().glPointSize(pointSize);
		GLDevice.getGL().glColor4f(pointColor.getRf(), pointColor.getGf(),
				pointColor.getBf(), pointColor.getAf());
		GLDevice.getGL().glDrawArrays(GL10.GL_POINTS, 0, 1);
		GLDevice.getGL().glDisableClientState(GL10.GL_VERTEX_ARRAY);
		if (pointColor.hasAlpha())
			GLDevice.disableBlend();
	}

	@Override
	public void render() {
		// TODO Auto-generated method stub
		drawPoint();
	}

	@Override
	public void update() {
		// TODO Auto-generated method stub
	}

}
